﻿using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using Tanis.DataModels;
using Tanis.RouteService;
using System.Windows.Media;

namespace Tanis.Controls
{
	public partial class RouteDetailsControl
	{
        public Brush ThemeDependantListBoxColor { get { return new SolidColorBrush(ThemeHelper.ThemeDependantListBoxColor); } }
        public Brush ThemeDependantColor { get { return new SolidColorBrush(ThemeHelper.ThemeDependantColor); } }
        public Brush ThemeDependantColorInverted { get { return new SolidColorBrush(ThemeHelper.ThemeDependantColorInverted); } }

		public RouteSummary RouteSummary
		{
			set
			{
				RouteTimeSummary.Text = value.TimeSummary;
                DescriptionComposite.ItemsSource = value.RouteDescriptionComposite;

				ObservableCollection<Segment> segments = value.Route.Segments;
				List<RouteDetails> details = segments.OfType<BusRideSegment>().Select(detail => new RouteDetails(detail)).ToList();
                RouteDetails = details.FirstOrDefault();
				_routeDetailCtrl.ItemsSource = details;                
			}
		}

        public RouteDetails RouteDetails
        {
            get; set;
        }

		public RouteDetailsControl()
		{
			InitializeComponent();
            _routeDetailCtrl.SelectionChanged += RouteDetailsListBoxSelectionChanged;
		}

        private void RouteDetailsListBoxSelectionChanged(object sender, System.EventArgs e)
        {
            _routeDetailCtrl.SelectedIndex = -1;
        }
	}
}
